package data.mapper.implementation;


import java.util.LinkedList;

import data.mapper.Mapper;

/**
 * This is a mapper composed by a serie of mappers
 * @author denoyer
 *
 * @param <A>
 * @param <B>
 */

public class Mapper_FromMappers<A, B> implements Mapper<A,B>{

	@SuppressWarnings("unchecked")
	protected LinkedList<Mapper> mappers;
	
	@SuppressWarnings("unchecked")
	public Mapper_FromMappers()
	{
		mappers=new LinkedList<Mapper>();
	}
	
	@SuppressWarnings({ "unchecked", "unchecked", "unchecked" })
	public B map(A from) {
		Object o=from;
		int n=0;
		for(Mapper m:mappers)
		{
			o=m.map(o);
			if (o==null) return(null);
		}
		return((B)o);		
	}
	
	@SuppressWarnings("unchecked")
	public void add(Mapper m)
	{
		mappers.addLast(m);
	}


}
